class SummaryRanges:
    def __init__(self):
        self.memory = [[float("-inf"), float("-inf")], [float("inf"), float("inf")]]

    def addNum(self, val: int) -> None:
        i = 1
        while self.memory[i][0] < val:
            i += 1
        if self.memory[i-1][0] <= val <= self.memory[i-1][1] or self.memory[i][0] == val:
            return
        if self.memory[i-1][1] + 1 == val:
            self.memory[i-1][1] += 1
            if self.memory[i-1][1] + 1 == self.memory[i][0]:
                self.memory[i-1][1] = self.memory.pop(i)[1]
        elif self.memory[i][0] - 1 == val:
            self.memory[i][0] -= 1
        else:
            self.memory.insert(i, [val, val])

    def getIntervals(self) -> list:
        return self.memory[1:-1]


# Your SummaryRanges object will be instantiated and called as such:
# obj = SummaryRanges()
# obj.addNum(val)
# param_2 = obj.getIntervals()

a = SummaryRanges()
a.addNum(1)
print(a.getIntervals())
a.addNum(3)
print(a.getIntervals())
a.addNum(7)
print(a.getIntervals())
a.addNum(2)
print(a.getIntervals())
a.addNum(6)
print(a.getIntervals())
